// src/components/Navbar.js
import React from 'react';
import { useNavigate } from 'react-router-dom';
import '../assets/styles/Navbar.css';

const Navbar = ({ userData }) => {
  const navigate = useNavigate();

  const handleLogout = () => {
    localStorage.removeItem('token'); // 清除 token
    navigate('/login'); // 跳转到登录页面
  };

  return (
    <nav className="navbar">
      <div className="navbar-logo">
        <h2>链游九州</h2>
      </div>
      <div className="navbar-user">
        <p>欢迎, {userData.username} | {userData.email}</p>
        <button className="navbar-logout" onClick={handleLogout}>登出</button>
      </div>
    </nav>
  );
};

export default Navbar;

